import MyIcon from '@/components/MyIcon';

/***
 * 物料管理 -- <状态> -- 处理
 * @param state
 * */
export const stateOfRendering = (state: number | null | undefined, isShowIcon: boolean = true) => {
  if (typeof state !== 'number') return '--';
  if (state == 0) {
    return (
      <div>
        {isShowIcon && <MyIcon type="icon-dian" style={{ color: '#6812f2' }} />}&nbsp;
        <span>起草</span>
      </div>
    );
  } else if (state == 1) {
    return (
      <div>
        {isShowIcon && <MyIcon type="icon-dian" style={{ color: '#2390fd' }} />}&nbsp;
        <span>审核中</span>
      </div>
    );
  } else if (state == 2) {
    return (
      <div>
        {isShowIcon && <MyIcon type="icon-dian" style={{ color: '#59d6a5' }} />}&nbsp;
        <span>有效</span>
      </div>
    );
  } else {
    return (
      <div>
        {isShowIcon && <MyIcon type="icon-dian" style={{ color: '#5c6f91' }} />}&nbsp;
        <span>作废</span>
      </div>
    );
  }
};

/***
 * 物料管理 -- <签发方式> -- 处理
 * @param state
 * */
export const signTypeOfRendering = (state: number | null | undefined) => {
  if (typeof state !== 'number') return '--';
  if (state == 0)
    return (
      <div>
        <span style={{ color: '#ad69f5' }}>直接签发</span>
      </div>
    );
  else
    return (
      <div>
        <span style={{ color: '#f49609' }}>审核签发</span>
      </div>
    );
};

/***
 * 物料管理 -- <审核状态> -- 处理  返回div
 * @param state
 * */
export const signStateOfRendering = (state: number | null | undefined) => {
  return state == 0 ? '起草' : state == 1 ? '审核中' : state == 2 ? '有效' : state == 3 ? '作废' : '--';

  // if (typeof state !== 'number') return '--';
  // if (state == 0)
  //   return (
  //     <div>
  //       <span style={{ color: '#4246d1' }}>待审核</span>
  //     </div>
  //   );
  // else if (state == 1)
  //   return (
  //     <div>
  //       <span style={{ color: '#1e9392' }}>通过</span>
  //     </div>
  //   );
  // else if (state == 2)
  //   return (
  //     <div>
  //       <span style={{ color: '#9d3df0' }}>驳回</span>
  //     </div>
  //   );
  // else
  //   return (
  //     <div>
  //       <span style={{ color: '#5c6f91' }}>作废</span>
  //     </div>
  //   );
};

/***
 * 物料管理 -- <审核状态> -- 处理  返回span
 * @param state
 * */
export const signStateOfRenderings = (state: number | null | undefined) => {
  if (typeof state !== 'number') return '--';
  if (state == 0) {
    return <span style={{ color: '#4246d1' }}>待审核</span>;
  } else if (state == 1) {
    return <span style={{ color: '#1e9392' }}>通过</span>;
  } else if (state == 2) {
    return <span style={{ color: '#9d3df0' }}>驳回</span>;
  } else {
    return <span style={{ color: '#5c6f91' }}>作废</span>;
  }
};

/**
 * 处理返回变色的DOM
 * @param text
 * @returns
 */
export const getColorTextDoms = (text: any) => {
  if (text) {
    const [colorText, color] = text?.split('||');
    return (
      <>
        <span style={{ color: color }}>{colorText || '--'}</span>
      </>
    );
  } else {
    return <span>--</span>;
  }
};

/**
 * 处理省市县
 * @param resObj
 * @returns
 */
export const disposeArea = (resObj: Record<string, any>): any => {
  /***处理省市县**/
  if (resObj?.contaNode?.length) {
    let CodeArr = [...resObj?.contaNode];
    resObj.provinceCode = CodeArr?.[0];
    resObj.cityCode = CodeArr?.[1];
    resObj.countyCode = CodeArr?.[2];
  }
  return resObj;
};
